#ifndef __processPool_H__
#define __processPool_H__

#include "func.h"

#define MAXCONNS 100
#define BUFFERSIZE 4096

typedef struct processChild{
    pid_t pid;  //子进程的pid
    int pipefd;  //管道的一端,sockerpair的全双工匿名管道
    short busy;  //子进程是否忙碌，1代表忙碌，0代表空闲
}processChild;

typedef struct processPool_t {
    int processNum;  //未知数组大小
    processChild* proChild;
}processPool_t;

void processPool_tInit(processPool_t* pPool, struct epoll_event** pevtList);
void processPool_tDestroy(processPool_t* pPool, struct epoll_event* pevtList);

//记录日志
void clientlog(char *msg);

//processPool相关操作
void makeChild(processPool_t* pPool);
void childHandleTask(int pipefd);
//子进程关联父进程中的文件对象
//socketpair + sendmsg/recvmsg
int sendFd(int pipefd, int fd);//成功返回0
int recvFd(int pipefd);//返回文件描述符，关联父进程中的文件对象
void eventsHappen(int nready, struct epoll_event* pevtList, int listenfd, processPool_t* pPool);


//epoll相关操作
void setNonBlock(int fd);
int tcpServerInit(const char* cp, uint16_t sin_port); //cp为传入参数
void newConnect(int listenfd, int epfd);
void readEvent(int fd, int epfd);


void epollAddEvent(int epfd, int listenfd, uint32_t events);
void epollModEvent(int epfd, int listenfd, uint32_t events);
void epollDelEvent(int epfd, int listenfd, uint32_t events);

#endif
